Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pure Haskell implementation #631

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

hsyl20
Copy link
Contributor

@hsyl20 hsyl20 commented Dec 11, 2023

Add pure Haskell implementation for use with the JS backend. Use same Cabal flag as text package (-fpure-haskell).

@hsyl20
Copy link
Contributor Author

hsyl20 commented Dec 11, 2023

CI is finally passing. I've added a new job with the -fpure-haskell flag. Reviews welcome!

Copy link
Member

@clyring clyring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more to come

.github/workflows/ci.yml Outdated Show resolved Hide resolved
Data/ByteString/Builder/RealFloat/D2S.hs Outdated Show resolved Hide resolved
Data/ByteString/Builder/RealFloat/F2S.hs Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Builder/Prim/Internal/Base16.hs Outdated Show resolved Hide resolved
Data/ByteString/Builder/RealFloat/Internal.hs Show resolved Hide resolved
Data/ByteString/Internal.hs Outdated Show resolved Hide resolved
bytestring.cabal Outdated Show resolved Hide resolved
include/bytestring-cpp-macros.h Outdated Show resolved Hide resolved
@clyring clyring linked an issue Dec 12, 2023 that may be closed by this pull request
@hsyl20
Copy link
Contributor Author

hsyl20 commented Jan 8, 2024

Thanks @clyring for the review! It's now ready for a second round :-)

Copy link

@doyougnu doyougnu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments. Mostly around excess bangs.

Data/ByteString/Builder/RealFloat/F2S.hs Show resolved Hide resolved
Data/ByteString/Builder/RealFloat/F2S.hs Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
bytestring.cabal Outdated Show resolved Hide resolved
@hsyl20
Copy link
Contributor Author

hsyl20 commented Jan 12, 2024

Thanks @doyougnu for the review. I've fixed everything I believe. I've also added INLINABLE pragmas so that specialization kicks in for CInt and CLong variants of decode[Uns/S]ignedBlah. Now Core looks pretty good.

@hsyl20
Copy link
Contributor Author

hsyl20 commented Jan 16, 2024

Any chance we can get this merged and released before the GHC 9.10 fork?

@clyring
Copy link
Member

clyring commented Jan 16, 2024

Perhaps it can be merged by then but I don't think there's any reason to cut a release so soon.

Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Show resolved Hide resolved
Data/ByteString/Internal/Type.hs Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Show resolved Hide resolved
bytestring.cabal Outdated Show resolved Hide resolved
bytestring.cabal Show resolved Hide resolved
include/bytestring-cpp-macros.h Outdated Show resolved Hide resolved
bytestring.cabal Outdated Show resolved Hide resolved
Data/ByteString/Internal/Type.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Comment on lines 268 to 275
-- we cannot negate directly as 0 - (minBound :: Int) = minBound
-- So we write the sign and the first digit.
pokeByteOff buf 0 '-'
let !(q,r) = quotRem x (-10)
putDigit buf 1 (fromIntegral (abs r))
case q of
0 -> pure (plusPtr buf 2)
_ -> decodeUnsignedDec' q (plusPtr buf 1) (plusPtr buf 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gross! We can negate directly, so long as we cast to the appropriate unsigned type. (I know you got this logic directly from the C code, and it's even worse there because we can expect the C compiler to produce better code for unsigned-known-divisor quotRem anyway. ...follow-up work?)

Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@clyring clyring added this to the 0.12.1.0 milestone Jan 30, 2024
@clyring
Copy link
Member

clyring commented Feb 1, 2024

Go ahead and just add {-# LANGUAGE TypeApplications #-} where-ever it's convenient rather than trying to avoid them. Also, if you pull in the latest master that will fix the FreeBSD CI job.

hubot pushed a commit to ghc/ghc that referenced this pull request Feb 1, 2024
...mostly so that 16d6b7e835ffdcf9b894e79f933dd52348dedd0c
(which reworks unaligned writes in Builder) and the stuff in
haskell/bytestring#631 can see wider testing.

The less-terrible code for unaligned writes used in Builder on
hosts not known to be ulaigned-friendly also takes less effort
for GHC to compile, resulting in a metric decrease for T21839c
on some platforms.

The metric increase on T21839r is caused by the unrelated commit
750dac33465e7b59100698a330b44de7049a345c.  It perhaps warrants
further analysis and discussion (see #23822) but is not critical.

Metric Decrease:
T21839c
Metric Increase:
T21839r
@clyring
Copy link
Member

clyring commented Feb 1, 2024

I plan to give this another round of review in a day or two.

hubot pushed a commit to ghc/ghc that referenced this pull request Feb 1, 2024
...mostly so that 16d6b7e835ffdcf9b894e79f933dd52348dedd0c
(which reworks unaligned writes in Builder) and the stuff in
haskell/bytestring#631 can see wider testing.

The less-terrible code for unaligned writes used in Builder on
hosts not known to be ulaigned-friendly also takes less effort
for GHC to compile, resulting in a metric decrease for T21839c
on some platforms.

The metric increase on T21839r is caused by the unrelated commit
750dac33465e7b59100698a330b44de7049a345c.  It perhaps warrants
further analysis and discussion (see #23822) but is not critical.

Metric Decrease:
T21839c
Metric Increase:
T21839r
hubot pushed a commit to ghc/ghc that referenced this pull request Feb 2, 2024
...mostly so that 16d6b7e835ffdcf9b894e79f933dd52348dedd0c
(which reworks unaligned writes in Builder) and the stuff in
haskell/bytestring#631 can see wider testing.

The less-terrible code for unaligned writes used in Builder on
hosts not known to be ulaigned-friendly also takes less effort
for GHC to compile, resulting in a metric decrease for T21839c
on some platforms.

The metric increase on T21839r is caused by the unrelated commit
750dac33465e7b59100698a330b44de7049a345c.  It perhaps warrants
further analysis and discussion (see #23822) but is not critical.

Metric Decrease:
T21839c
Metric Increase:
T21839r
hubot pushed a commit to ghc/ghc that referenced this pull request Feb 2, 2024
...mostly so that 16d6b7e835ffdcf9b894e79f933dd52348dedd0c
(which reworks unaligned writes in Builder) and the stuff in
haskell/bytestring#631 can see wider testing.

The less-terrible code for unaligned writes used in Builder on
hosts not known to be ulaigned-friendly also takes less effort
for GHC to compile, resulting in a metric decrease for T21839c
on some platforms.

The metric increase on T21839r is caused by the unrelated commit
750dac33465e7b59100698a330b44de7049a345c.  It perhaps warrants
further analysis and discussion (see #23822) but is not critical.

Metric Decrease:
T21839c
Metric Increase:
T21839r
hubot pushed a commit to ghc/ghc that referenced this pull request Feb 3, 2024
...mostly so that 16d6b7e835ffdcf9b894e79f933dd52348dedd0c
(which reworks unaligned writes in Builder) and the stuff in
haskell/bytestring#631 can see wider testing.

The less-terrible code for unaligned writes used in Builder on
hosts not known to be ulaigned-friendly also takes less effort
for GHC to compile, resulting in a metric decrease for T21839c
on some platforms.

The metric increase on T21839r is caused by the unrelated commit
750dac33465e7b59100698a330b44de7049a345c.  It perhaps warrants
further analysis and discussion (see #23822) but is not critical.

Metric Decrease:
T21839c
Metric Increase:
T21839r
Data/ByteString/Builder/RealFloat/D2S.hs Outdated Show resolved Hide resolved
Data/ByteString/Builder/RealFloat/F2S.hs Show resolved Hide resolved
Data/ByteString/Internal/Type.hs Show resolved Hide resolved
Data/ByteString/Short/Internal.hs Show resolved Hide resolved
Data/ByteString/Short/Internal.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
hubot pushed a commit to ghc/ghc that referenced this pull request Feb 5, 2024
...mostly so that 16d6b7e835ffdcf9b894e79f933dd52348dedd0c
(which reworks unaligned writes in Builder) and the stuff in
haskell/bytestring#631 can see wider testing.

The less-terrible code for unaligned writes used in Builder on
hosts not known to be ulaigned-friendly also takes less effort
for GHC to compile, resulting in a metric decrease for T21839c
on some platforms.

The metric increase on T21839r is caused by the unrelated commit
750dac33465e7b59100698a330b44de7049a345c.  It perhaps warrants
further analysis and discussion (see #23822) but is not critical.

Metric Decrease:
T21839c
Metric Increase:
T21839r
@hsyl20
Copy link
Contributor Author

hsyl20 commented Feb 6, 2024

I've rebased to fix the conflict.

Copy link
Member

@clyring clyring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly there!

Data/ByteString/Internal/Type.hs Outdated Show resolved Hide resolved
Data/ByteString/Internal/Pure.hs Outdated Show resolved Hide resolved
bytestring used to rely on C functions. This patch adds equivalent
functions implemented in Haskell. The main purpose is for the JavaScript
backend to fully support bytestring.

Pure Haskell implementation can be enabled explicitly with a cabal flag.
It's automatically enabled for the JavaScript platform.

Thanks to Matthew Craven for the thorough review and the many
suggestions.

Co-authored-by: Matthew Craven <[email protected]>
@clyring
Copy link
Member

clyring commented Feb 7, 2024

@Bodigrim Did you also want to review?

@clyring
Copy link
Member

clyring commented Feb 7, 2024

@hasufell @angerman Do you know what's going on with the arm64v8 CI job? (And are you the right people to ping about this?) It's been consistently failing at the very end with:

A job completed hook has been configured by the self-hosted runner administrator
Error: /nix/store/42qhgz20lraczal3m9iwakwnmzrh67yc-hook-job-completed/bin/hook-job-completed is not a valid path to a script. Make sure it ends in '.sh', '.ps1' or '.js'.

@hasufell
Copy link
Member

hasufell commented Feb 7, 2024

Try to temporarily add the tag maerwald to the runner (in runs-on: [...].

@clyring
Copy link
Member

clyring commented Feb 7, 2024

I've done so at #658. The problem isn't specific to either PR; feel free to open another for experimentation.

@clyring clyring merged commit d497f39 into haskell:master Feb 7, 2024
25 of 26 checks passed
clyring pushed a commit that referenced this pull request Feb 7, 2024
bytestring used to rely on C functions. This patch adds equivalent
functions implemented in Haskell. The main purpose is for the JavaScript
backend to fully support bytestring.

Pure Haskell implementation can be enabled explicitly with a cabal flag.
It's automatically enabled for the JavaScript platform.

Thanks to Matthew Craven for the thorough review and the many
suggestions.

Co-authored-by: Matthew Craven <[email protected]>
(cherry picked from commit d497f39)
@angerman
Copy link
Contributor

angerman commented Feb 7, 2024

@hasufell @angerman Do you know what's going on with the arm64v8 CI job? (And are you the right people to ping about this?) It's been consistently failing at the very end with:

A job completed hook has been configured by the self-hosted runner administrator
Error: /nix/store/42qhgz20lraczal3m9iwakwnmzrh67yc-hook-job-completed/bin/hook-job-completed is not a valid path to a script. Make sure it ends in '.sh', '.ps1' or '.js'.

OMFG GitHub...

$ file /nix/store/42qhgz20lraczal3m9iwakwnmzrh67yc-hook-job-completed/bin/hook-job-completed
/nix/store/42qhgz20lraczal3m9iwakwnmzrh67yc-hook-job-completed/bin/hook-job-completed: a /nix/store/2w9vwv156cx1pi3dhg8yib5y8dan0xp2-bash-5.2-p15/bin/bash script, ASCII text executable

Alright, I'll give it a .sh suffix.

hubot pushed a commit to ghc/ghc that referenced this pull request Feb 19, 2024
...mostly so that 16d6b7e835ffdcf9b894e79f933dd52348dedd0c
(which reworks unaligned writes in Builder) and the stuff in
haskell/bytestring#631 can see wider testing.

The less-terrible code for unaligned writes used in Builder on
hosts not known to be ulaigned-friendly also takes less effort
for GHC to compile, resulting in a metric decrease for T21839c
on some platforms.

The metric increase on T21839r is caused by the unrelated commit
750dac33465e7b59100698a330b44de7049a345c.  It perhaps warrants
further analysis and discussion (see #23822) but is not critical.

Metric Decrease:
T21839c
Metric Increase:
T21839r

(cherry picked from commit 2702045)
hubot pushed a commit to ghc/ghc that referenced this pull request Feb 20, 2024
...mostly so that 16d6b7e835ffdcf9b894e79f933dd52348dedd0c
(which reworks unaligned writes in Builder) and the stuff in
haskell/bytestring#631 can see wider testing.

The less-terrible code for unaligned writes used in Builder on
hosts not known to be ulaigned-friendly also takes less effort
for GHC to compile, resulting in a metric decrease for T21839c
on some platforms.

The metric increase on T21839r is caused by the unrelated commit
750dac33465e7b59100698a330b44de7049a345c.  It perhaps warrants
further analysis and discussion (see #23822) but is not critical.

Metric Decrease:
T21839c
Metric Increase:
T21839r

(cherry picked from commit 2702045)
hubot pushed a commit to ghc/ghc that referenced this pull request Feb 20, 2024
...mostly so that 16d6b7e835ffdcf9b894e79f933dd52348dedd0c
(which reworks unaligned writes in Builder) and the stuff in
haskell/bytestring#631 can see wider testing.

The less-terrible code for unaligned writes used in Builder on
hosts not known to be ulaigned-friendly also takes less effort
for GHC to compile, resulting in a metric decrease for T21839c
on some platforms.

The metric increase on T21839r is caused by the unrelated commit
750dac33465e7b59100698a330b44de7049a345c.  It perhaps warrants
further analysis and discussion (see #23822) but is not critical.

Metric Decrease:
T21839c
Metric Increase:
T21839r

(cherry picked from commit 2702045)
hubot pushed a commit to ghc/ghc that referenced this pull request Feb 20, 2024
...mostly so that 16d6b7e835ffdcf9b894e79f933dd52348dedd0c
(which reworks unaligned writes in Builder) and the stuff in
haskell/bytestring#631 can see wider testing.

The less-terrible code for unaligned writes used in Builder on
hosts not known to be ulaigned-friendly also takes less effort
for GHC to compile, resulting in a metric decrease for T21839c
on some platforms.

The metric increase on T21839r is caused by the unrelated commit
750dac33465e7b59100698a330b44de7049a345c.  It perhaps warrants
further analysis and discussion (see #23822) but is not critical.

Metric Decrease:
T21839c
Metric Increase:
T21839r

(cherry picked from commit 2702045)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compatibility with GHC's JavaScript backend
6 participants